<!--
 * @Author: linZeJian
 * @Date: 2022-08-24 10:53:55
 * @LastEditors: linZeJian
 * @LastEditTime: 2022-11-08 09:45:43
 * @Description: 
-->
<template>
  <div v-if="option.display">
    <uni-forms-item
      :label="option.label"
      :required="option.required"
      :rules="[{ required: option.required, errorMessage: '必填项不能为空' }]"
      :name="option.prop"
    >
      <uni-data-checkbox
        v-model="comValue"
        multiple
        :placeholder="
          option.placeholder ? option.placeholder : '请选择' + option.label
        "
        :style="detailValue ? 'pointer-events: none;' : ''"
        :disabled="detailValue"
        :localdata="option.dicData"
        :map="{ text: option.props.label, value: option.props.value }"
      />
    </uni-forms-item>
  </div>
</template>

<script>
export default {
  name: "auni-checkbox",
  props: {
    option: Object,
    value: [String, Number, Array],
  },
  data() {
    return {};
  },
  computed: {
    comValue: {
      get() {
        // console.log("this.option :>> ", this.option);
        // console.log("this.value :>> ", this.value);
        // 处理多选框绑定值字符串转数组
        if (this.value == "" || this.value == undefined) {
          let valueArray = [];
          return valueArray;
        } else if (
          Object.prototype.toString
            .call(this.value)
            .slice(8, -1)
            .toLowerCase() == "array"
        ) {
          return this.value;
        } else {
          let valueArray = [];
          let valueSplit = this.value.split(",");
          valueArray = [...valueSplit];
          return valueArray;
        }
        // return this.value;
      },
      set(val) {
        // 触发value绑定值的交互与更新
        this.$emit("input", val);
      },
    },
    // 处理详情模式
    detailValue() {
      if (this.option.detail) {
        return true;
      } else {
        return false;
      }
    },
  },
  created() {},
  watch: {
    value: {
      deep: true,
      immediate: true,
      handler(newV) {},
    },
  },
  methods: {},
};
</script>

<style></style>
